//
// Created by francklinson on 2021/7/25 AT 23:28.
//
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    // 双指针
    int maxOperations(vector<int> &nums, int k) {
        sort(nums.begin(), nums.end());
        int left = 0, right = nums.size() - 1, ans = 0;
        while (left < right) {
            if (nums[left] + nums[right] == k) {
                ++left;
                --right;
                ++ans;
            } else if (nums[left] + nums[right] < k) ++left;
            else --right;
        }
        return ans;
    }
};

int main() {
    vector<int> nums{3, 1, 3, 4, 3};
    Solution solution;
    cout << solution.maxOperations(nums, 6) << endl;
    return 0;
}

